package com.swt.gap.controller;

import com.swt.gap.common.graph.GraphNeo4jVO;
import com.swt.gap.model.vo.graph.*;
import com.swt.gap.service.GraphNodeService;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author sx
 */

@Api(tags = "图谱节点，档案")
@RestController
@RequestMapping("/graph/node")
public class GraphNodeController {

    private final GraphNodeService graphNodeService;

    public GraphNodeController(GraphNodeService graphNodeService) {
        this.graphNodeService = graphNodeService;
    }


    @ApiOperation(value = "档案，概览", notes = "档案概览,实体、事件、文档共用")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeInfoVO.class)
    })
    @GetMapping("/overview")
    public ResponseEntity<NodeInfoVO> getNodeInfo(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeInfo(nodeId));
    }

    @ApiOperation(value = "档案，属性", notes = "档案属性,实体、事件、文档共用")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeProperty.class, responseContainer = "List")
    })
    @GetMapping("/property")
    public ResponseEntity<List<NodeProperty>> listNodeProperties(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.listNodeProperties(nodeId));
    }

    @ApiOperation(value = "档案，关系", notes = "档案关系")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeRelationshipsVO.class, responseContainer = "List")
    })
    @GetMapping("/relations")
    public ResponseEntity<List<NodeRelationshipsVO>> getNodeRelations(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getRelationNode(nodeId));
    }

    @ApiOperation(value = "档案，关联实体", notes = "关联档案实体")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeEntity.class, responseContainer = "List")
    })
    @GetMapping("/entity")
    public ResponseEntity<List<NodeEntity>> getNodeRelEntity(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeRelEntity(nodeId));
    }

    @ApiOperation(value = "档案，关联事件", notes = "档案关联事件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeEventVO.class, responseContainer = "List")
    })
    @GetMapping("/event")
    public ResponseEntity<List<NodeEventVO>> getNodeRelEvent(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeRelEvent(nodeId));
    }

    @ApiOperation(value = "档案，关联文档", notes = "档案关联文档")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeDocVO.class, responseContainer = "List")
    })
    @GetMapping("/doc")
    public ResponseEntity<List<NodeDocVO>> getNodeRelDoc(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeRelDoc(nodeId));
    }

    @ApiOperation(value = "档案，文档内容", notes = "档案文档内容")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeDocVO.class)
    })
    @GetMapping("/doc-content")
    public ResponseEntity<NodeDocVO> getNodeRelDocContent(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeRelDocContent(nodeId));
    }




    @ApiOperation(value = "关联实体", notes = "关联实体")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.Node.class, responseContainer = "List")
    })
    @GetMapping("/rel-entity")
    public ResponseEntity<List<GraphNeo4jVO.Node>> getNodeRelEntityRetGraphNode(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeRelEntityRetGraphNode(nodeId));
    }

    @ApiOperation(value = "关联事件", notes = "关联事件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.Node.class, responseContainer = "List")
    })
    @GetMapping("/rel-event")
    public ResponseEntity<List<GraphNeo4jVO.Node>> getNodeRelEventRetGraphNode(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeRelEventRetGraphNode(nodeId));
    }

    @ApiOperation(value = "关联文档", notes = "关联文档")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.Node.class, responseContainer = "List")
    })
    @GetMapping("/rel-doc")
    public ResponseEntity<List<GraphNeo4jVO.Node>> getNodeRelDocRetGraphNode(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.getNodeRelDocRetGraphNode(nodeId));
    }

    @ApiOperation(value = "获取文档节点内容", notes = "根据属性，获取文档节点内容")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Map", name = "props", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = NodeDocVO.class)
    })
    @PostMapping("/doc-content")
    public ResponseEntity<NodeDocVO> getContentByNode(@RequestBody Map<String, Object> props) {
        return ResponseEntity.ok(graphNodeService.getContentByNode(props));
    }


    @GetMapping("/info")
    @ApiOperation(value = "根据名称 获取节点详情", notes = "根据名称 获取节点详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeName", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.Node.class,responseContainer = "List")
    })
    public ResponseEntity<List<GraphNeo4jVO.Node>> listNodeByName(@RequestParam String nodeName) {
        return ResponseEntity.ok(graphNodeService.listNodeByName(nodeName));
    }


    @GetMapping("/rel-node")
    @ApiOperation(value = "根据id获取1度关系", notes = "根据id获取1度关系， 关联节点，除去事件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.class)
    })
    public ResponseEntity<GraphNeo4jVO> list1lPath(@RequestParam String nodeId) {
        return ResponseEntity.ok(graphNodeService.list1Path(nodeId));
    }

    @GetMapping("/media-node/info")
    @ApiOperation(value = "根据名称 获取多媒体节点详情", notes = "根据名称 获取多媒体节点详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeName", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.Node.class,responseContainer = "List")
    })
    public ResponseEntity<List<GraphNeo4jVO.Node>> listMediaNodeByName(@RequestParam String nodeName) {
        return ResponseEntity.ok(graphNodeService.listMediaNodeByName(nodeName));
    }
}
